using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Globalization;
using System.Xml.Serialization;

namespace ThaiLanguageTools.DataStruct
{
    public class XWordInfo : IComparable
    {
        [XmlAttribute("w")]
        public String Text;

        [XmlAttribute("pos")]
        public String PartOfSpeech;

        [XmlIgnore]
        public bool PartOfSpeechSpeficied 
        {
            get { return String.IsNullOrEmpty(PartOfSpeech); } 
            set { } // framework bug
        }
        
        [XmlAttribute("lang")]
        public String Language;

        public XWordInfo() { } // XML

        public XWordInfo(String text, String languageName) : this (text, languageName, null) { }

        public XWordInfo(String text, String languageName, String partOfSpeech)
        {
            Text = text;
            Language = languageName;
            PartOfSpeech = partOfSpeech;
        }


        public override string ToString()
        {
            return Text + (String.IsNullOrEmpty(PartOfSpeech) ? "" : "/"+PartOfSpeech) +" ("+Language+")";
        }

        #region IComparable Members

        public int CompareTo(object obj)
        {
            XWordInfo that = obj as XWordInfo;
            if (that == null) { return -1; }

            int lc = this.Language.CompareTo(that.Language);
            if (lc != 0) { return lc; }
            return this.Text.CompareTo(that.Text);
        }

        #endregion
    }
}
